import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:get/get.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    final themeData = ThemeData(
      elevatedButtonTheme: ElevatedButtonThemeData(
        style: ElevatedButton.styleFrom(
          backgroundColor: Colors.black,
        ),
      ),
    );

    return GetMaterialApp(
      // 使用 GetMaterialApp
      title: 'Flutter Demo',
      theme: themeData,
      home: HomeScreen(), // 设置 HomeScreen 作为首页
    );
  }
}

class CounterController extends GetxController {
  var count = 0.obs; // 使用.obs 将变量变成响应式的
  void increment() {
    count++;
  }
}

class CounterScreen extends StatelessWidget {
  // 每个页面内都会创建 CounterController.
  final CounterController controller = Get.put(CounterController());

  CounterScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          children: [
            Obx(() {
              // Obx 是用于监听响应式变量的组件
              return Text(
                'Counter: ${controller.count}',
                style: TextStyle(fontSize: 30),
              );
            }),

            TextButton(onPressed: Get.back, child: Text("Back")),

            TextButton(
              onPressed: controller.increment,
              child: Text("Increment"),
            ),
          ],
        ),
      ),
    );
  }
}

class HomeScreen extends StatelessWidget {
  const HomeScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Home Page')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(
              "Hello, Flutter!",
              style: TextStyle(
                fontSize: 24, // 设置字体大小
                color: Colors.blue, // 设置字体颜色
                fontWeight: FontWeight.bold, // 设置字体粗细
                fontStyle: FontStyle.italic, // 设置字体样式为斜体
                letterSpacing: 2.0, // 设置字母间距
                wordSpacing: 4.0, // 设置单词间距
                decoration: TextDecoration.underline, // 添加下划线
                decorationColor: Colors.red, // 设置装饰线颜色
                decorationStyle: TextDecorationStyle.dotted, // 设置装饰线样式
              ),
            ),
            ElevatedButton(
            style: ElevatedButton.styleFrom(backgroundColor: Colors.yellow),
              onPressed: () {
                Get.to(() => CounterScreen());
              },
              child: const Text("Go to Counter Page 1"),
            ),
            ElevatedButton(
              onPressed: () {
                Get.to(() => CounterScreen());
              },
              child: const Text("Go to Counter Page 2"),
            ),
            ElevatedButton(
              onPressed: () {
                Get.to(() => CounterScreen());
              },
              child: const Text("Go to Counter Page 3"),
            ),
          ],
        ),
      ),
    );
  }
}
